<?php
$title='帖子管理';
define('IN_TG', 'admin_article');
include('admin_header.php');
//判断是否存在p参数，存在则使用传递来的页码，不存在则使用默认值1
$page=isset($_GET['p'])?$_GET['p']:1;
$sql = "select tg_id,tg_type,tg_title,tg_username,tg_date,tg_readcount,tg_commendcount,tg_nice,tg_last_modify_date from tg_article as a where tg_reid=0 order by tg_id limit ".intval(($page-1)*10).",10";
$res = _query($sql);
$sql="select tg_id from tg_article where tg_reid=0";
$total=_num_rows(_query($sql));
$page_total=ceil($total/10);
?>
<div class="row">
    <div class="col-lg-12">
        <h1>多用户留言 <small>后台管理系统</small></h1>
        <ol class="breadcrumb">
            <li><a href="admin_index.php"><i class="fa fa-home"></i> 首页</a></li>
            <li class="active"><i class="fa fa-table"></i> <?php echo $title;?></li>
        </ol>
        <div class="alert alert-info alert-dismissable" id="article_warming_alert" style="display: none">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
            <span id="article_warming"></span>
        </div>
    </div>
</div><!-- /.row -->

<div class="row">
    <div class="col-lg-12">
        <div class="table-responsive">
            <table class="table table-bordered table-hover tablesorter">
                <thead>
                <tr>
                    <th>ID <i class="fa fa-sort"></i></th>
                    <th>标题 <i class="fa fa-sort"></i></th>
                    <th>发帖人 <i class="fa fa-sort"></i></th>
                    <th>发帖时间 <i class="fa fa-sort"></i></th>
                    <th>阅读量 <i class="fa fa-sort"></i></th>
                    <th>评论量 <i class="fa fa-sort"></i></th>
                    <th>上次修改时间 <i class="fa fa-sort"></i></th>
                    <th>是否为精华 </th>
                </tr>
                </thead>
                <tbody>
                <?php while($row = _fetch_array_list($res)): ?>
                    <tr>
                        <td><?php echo $row['tg_id'];?></td>
                        <td><img src="images/icon<?php echo $row['tg_type'];?>.gif"> <?php echo $row['tg_title'];?></td>
                        <td><?php echo $row['tg_username'];?></td>
                        <td><?php echo $row['tg_date'];?></td>
                        <td><?php echo $row['tg_readcount'];?></td>
                        <td><?php echo $row['tg_commendcount'];?></td>
                        <td><?php echo $row['tg_last_modify_date']=='0000-00-00 00:00:00'?'暂未修改':$row['tg_last_modify_date'];?></td>
                        <td class="text-center">
                            <?php if($row['tg_nice']==1):?>
                                <i class="fa fa-check"></i>
                            <?php else:?>
                                <i class="fa fa-times"></i>
                            <?php endif;?>
                        </td>
                    </tr>
                <?php endwhile;?>
                </tbody>
            </table>
            <div class="text-right">
                <ul class="pagination pagination-lg">
                    <li <?php if($page==1):?>class="disabled" <?php endif;?>><a href="?p=1">«</a></li>
                    <?php for($i=1;$i<=$page_total;$i++)
                    {
                        if ($page == $i) {
                            echo '  <li class="active"><a href="?p='.$i.'">'.$i.'</a></li>';
                        } else {
                            echo '  <li><a href="?p='.$i.'">'.$i.'</a></li>';
                        }
                    }
                    ?>
                    <li <?php if($page==$page_total):?>class="disabled" <?php endif;?>><a href="?p=<?php echo $page_total;?>">»</a></li>
                </ul>
            </div>
        </div>
    </div>
</div><!-- /.row -->



</div><!-- /#page-wrapper -->
<?php include('admin_footer.php');?>
<script>
    $("#admin_article").attr('class','active')
</script>